import React from 'react';
import {Table, Button, Icon, Pagination, Row, Col, Form } from 'antd';

let List = React.createClass({

  getInitialState() {
    return {
      data: []
    }
  },

  componentWillReceiveProps(nextProps) {
    console.log(nextProps);
    if (nextProps.record) {
      this.setState({data: nextProps.record,tenementContractId: nextProps.tenementContractId})
    }
  },

  //删除
  delete(record) {
    let id = record.indexForSort;
    let data = this.state.data;
    let newData = [];
    data.forEach((item) => {
      if (item.indexForSort !== id) {
        newData.push(item)
      }
    })
    this.setState({
      data: newData
    })
    this.props.synchronMethod(newData);
  },

  rowkey(data) {
    return data.indexForSort;
  },

  render () {
    
    const columns = [
      {
        title: '房屋租金',
        dataIndex: 'rent'
      }, {
        title: '合约开始日期',
        dataIndex: 'startTime'
      }, {
        title: '合约结束日期',
        dataIndex: 'expireTime'
      },
      {
        title: '阶段合计',
        dataIndex: 'totalRent',
      }, {
        title: '操作',
        width: 100,
        render: (text, record) => {
          return (
            <div>        
              <Button  className="ant-btn-icon" onClick={this.delete.bind(this, record)} ><Icon type="delete" /></Button>
            </div>
          )
        }
      }
    ];

    return (
      <div style={{margin: '0 10%'}} >
        <Table size="middle" rowKey={this.rowkey} columns={columns} dataSource={this.props.record} pagination={ false }/>
      </div>
    );
  }
});
export default List